<?php
/**
 * User: jewens
 */
class Test extends CI_Controller
{
    public function tt()
    {
        $this->load->service('direct_seeding/service_direct_seeding_mixed_flow');
        $data = $this->service_direct_seeding_mixed_flow->index(1819, DIRECT_SEEDING_MIXED_FLOW_TYPE_ENABLE);
        p('aaa', $data);



    }


    public function index()
    {
        $this->load->service('message/service_message_push');
        
        $this->load->model('auction/Model_auction', 'a');
        
        $item = $this->a->getById(1);
        
    	$replace_content = array(
    			'#anchor_name#' => $item['uname'],
    			'#auction_name#' => $item['win_uname'],
    			'#play_time#'=> date('m月d日H点i分', strtotime($item['play_time'])),
    			'#amount#'=> $item['win_amount'],
    			'#title#' => $item['title'],
    	);
    	$data = $this->service_message_push->realname_auth_success('101111111110228');
    	
    	//副主播推送通知
    	//$data = $this->service_message_push->auction_success_auction($item['uid'], array('aid'=>$item['aid'], 'cid'=>$item['cid']), $replace_content);
    	
        
        //$data = $this->service_message_push->wait_apply_handshake('202', array('aid'=>'4', 'cid'=>'1', 'cid'=>'1'));
        
        //$data = $this->service_message_push->start_prefix_direct_seeding('202', array('ds_id'=>'4', 'title'=>'title'));
        
        
        //$data = $this->service_message_push->start_direct_seeding('202', array('ds_id'=>'4', 'title'=>'title'));
        

        //$data = $this->service_message_push->confirm_apply_handshake('202', array('aid'=>'4', 'is_public'=>'0','is_charge'=>'1', 'amount'=>'50'));
        
        //$data = $this->service_message_push->passin_apply_handshake('202', array('aid'=>'4', 'title'=>'title'));
        
        
        print_r($data);
    }
    
    public function im()
    {
    	set_time_limit(0);
    	$this->load->service('message/service_message_im');
    	
    	$this->load->model('common/Model_dirty_words','dirty_words');
    	$data = $this->dirty_words->getAllLists(array(), true, 'id desc');
    	
    	foreach ($data as $v)
    	{
			$data = $this->service_message_im->openim_dirty_words(array($v['name']));
    	}
    }
    
    public function delete_dirty()
    {
    	set_time_limit(0);
    	$this->load->service('message/service_message_im');
    	 
    	//$data = $this->service_message_im->openim_dirty_words_delete(array('562','test'));
    	$data = $this->service_message_im->openim_dirty_words_get();
    	print_r($data);
    }
    
    public function reg()
    {
    	set_time_limit(0);
    	
    	$nickname = file_get_contents('../1.txt');
    	$nickname = mb_convert_encoding($nickname, "UTF8");
    	$nickname = explode("\n", $nickname);
    	
    	print_r($nickname);die();
    	
    	$header = array();
    	foreach (glob("../static/uploads/head/2/*") as $filename) {
    		$header[] = str_replace('../static', 'http://static.shikee.tv', $filename);
    	}
    	
    	
    	$this->load->model('user/Model_user', 'u');
    	$this->load->model('user/Model_user_info', 'ui');
    	foreach($nickname as $k=>$v)
    	{
    		if($v)
    		{
    			$data = array('uname'=>106001+$k,'nickname'=>$v,'header'=>$header[$k], 'source'=>5);
    			$uid = $this->u->save($data);
    			
    			$this->ui->save(array('uid'=>$uid, 'sex'=>2));
    		}
    		
    	}
    	
    }
    
    public function bat_reg()
    {
    	set_time_limit(0);
    	
    	$this->load->service('common/service_common_helper');
    	$list = $this->service_common_helper->read_xls('33.xls');
    	
    	//print_r($list);die();
    	$this->load->model('user/Model_user', 'u');
    	foreach($list as $k=>$v)
    	{
    		$user_item = $this->u->getOne(array('mobile' => $v[2]));
    		if(!$user_item)
    		{
    			//echo substr($v[1], -6);die();
    			$this->u->register($v[2], $v[0], $v[1], $v[2], '', '', USER_STATUS_NORMAL, 6);
    		}
    	}
    	 
    }
    
    public function nickname()
    {
    	set_time_limit(0);
    	
    	$this->load->model('user/Model_user', 'u');
    	
    	$list = $this->u->getAllLists(array('source'=>5));
    	foreach($list as $k=>$v)
    	{
    		$this->u->save(array('nickname'=>str_replace("\r", '', $v['nickname'])), $v['uid']);
    	}
    	 
    }
    
    public function set_cache()
    {
    	$this->load->driver('cache');
    	$rs = $this->cache->redis->save('test', '111');
    	var_dump($rs);
    }
    
    public function get_cache()
    {
    	$this->load->driver('cache');
    	$rs = $this->cache->redis->get('test');
    	var_dump($rs);
    	$rs = $this->cache->redis->cache_info();
    	var_dump($rs);
    }
    
    public function email()
    {
    	$data = array();
    	//$this->load->view('admin/report/email');
    	
       	$content = $this->load->view('admin/report/email', $data, true);
       	$this->load->library('mailer');
       	$this->mailer->sendmail(array('lyw@shikee.tv'), '报表 ', $content);
    }
    
    public function tests()
    {//p('sss');
        $this->load->service('finance/service_finance_tools');
        $ds_income = $this->service_finance_tools->ds_income(365);
        $anchor_income = isset($ds_income['data']['anchor_income']) ? $ds_income['data']['anchor_income'] : 0;
        $auction_income = isset($ds_income['data']['auction_income']) ? $ds_income['data']['auction_income'] : 0;


        $item = array
        (
            'duration'       => 12,//$v['duration'],
            'join_num'       => 24,//$v['join_num'],
            'anchor_income'  => $anchor_income,
            'auction_income' => $auction_income,
        );
        $this->load->service('message/service_message_im');
        $this->service_message_im->modify_group('@TGS#aTB5H72EP', array('notification' => json_encode($item)));

        exit;
        $this->load->service('finance/service_finance_tools');
        $ds_income = $this->service_finance_tools->ds_income(363);
        p($ds_income);
        set_time_limit(0);
        $item = array
        (
            'duration' => 10,
            'join_num' => 1280,
            'anchor_income' => 147,
            'auction_income' => 26,
        );
        $this->load->service('message/service_message_im');
        $this->service_message_im->modify_group('@TGS#aTB5H72EP', array('notification' => json_encode($item)));
exit;
        $this->load->service('message/service_message_im');
        $this->service_message_im->modify_group('@TGS#aTB5H72EP', array('notification' => 'test', 'introduction' => json_encode(array('a','b','c'))));
        //'notification'
    }
    
    public function phpinfo()
    {
    	phpinfo();
    }

    public function qc()
    {
    	$key = '127d4fe7e9f253375ad9e60e9315b5f8';
        $t = strtotime('+1 days');
    	$appid = '1253714904';
    	
    	$sign = md5($key.$t);

    	$url = "http://fcgi.video.qcloud.com/common_access?cmd=$appid&interface=Mix_StreamV2&t=$t&sign=$sign";
    	$data = array
        (
            'timestamp' => TIMESTAMP,
            'eventId'   => TIMESTAMP,
            'interface' => array
            (
                'interfaceName'=>"Mix_StreamV2",
                'para'=>array
                (
                    'app_id'    => $appid,# 填写直播APPID
                    "interface" => "mix_streamv2.start_mix_stream_advanced",# 接口名称
                    "mix_stream_session_id" => "9342_testing_1413_1",#填大主播的流ID
                    "output_stream_id"=> "9342_testing_1413_1",#填大主播的流ID

                    'output_stream_type' => 0,
                    //'mix_stream_template_id' => 310,
                    "input_stream_list"=>array
                    (
                        array
                        (
                            'input_stream_id' => 'stream',
                            'layout_params' => array
                            (
                                'image_layer' => 1,
                                'input_type' => 3,
                                'color' => '0xcc0033',
                                'image_width' => 960,# 小主播画面宽度
                                'image_height' => 544,# 小主播画面高度
                            ),
                        ),
                        #大主播：背景画面
                        array
                        (
                            'input_stream_id' => '9342_testing_1413_1',
                            'layout_params' => array
                            (
                                'image_layer' => 2,
                                //*
                                'image_width' => 480,# 小主播画面宽度
                                'image_height' => 540,# 小主播画面高度
                                'location_x' => 0,# x偏移：相对于大主播背景画面左上角的横向偏移
                                'location_y' => 0,# y偏移：相对于大主播背景画面左上角的纵向偏移
                                //*/
                            ),
                            //*
                            'crop_params' => array
                            (
                                'crop_width' => 480,#输入像素值
                                'crop_height' => 540,
                                'crop_x' => 480,
                                'crop_y' => 0,
                            ),
                            //*/
                        ),
                        //*

                        //*/
                        # 小主播1
                        array
                        (
                            'input_stream_id' => '9342_testing_1413_2',# 流ID
                            'layout_params'   => array
                            (
                                'image_layer' => 3,# 图层标识号：大画面填 1, 小画面依次填写2、3、4
                                //*
                                'image_width' => 480,# 小主播画面宽度
                                'image_height' => 544,# 小主播画面高度
                                'location_x' => 480,# x偏移：相对于大主播背景画面左上角的横向偏移
                                'location_y' => 0,# y偏移：相对于大主播背景画面左上角的纵向偏移
                                //*/
                            ),
                            'crop_params' => array
                            (
                                'crop_width' => 480,#输入像素值
					            'crop_height' => 540,
                                'crop_x' => 0,
                                'crop_y' => 0,
                            ),
                        ),
                    ),

                ),
            ),
        );

    	

    	$rs = $this->_sendRequest($url, json_encode($data));
    	p($rs, $data);
    }


    public function cancel()
    {
        $key = '127d4fe7e9f253375ad9e60e9315b5f8';
        $t = strtotime('+1 days');
        $appid = '1253714904';

        $sign = md5($key.$t);

        $url = "http://fcgi.video.qcloud.com/common_access?cmd=$appid&interface=Mix_StreamV2&t=$t&sign=$sign";
        $data = array
        (
            'timestamp' => TIMESTAMP,
            'eventId'   => TIMESTAMP,
            'interface' => array
            (
                'interfaceName'=>"Mix_StreamV2",
                'para'=>array
                (
                    'app_id'    => $appid,# 填写直播APPID
                    "interface" => "mix_streamv2.start_mix_stream_advanced",# 接口名称
                    "mix_stream_session_id" => "9342_testing_1189_1",#填大主播的流ID
                    "output_stream_id"=> "9342_testing_1189_1",#填大主播的流ID
                    'output_stream_type' => 0,
                    //'mix_stream_template_id' => 310,
                    "input_stream_list"=>array
                    (
                        #大主播：背景画面
                        array
                        (
                            'input_stream_id' => '9342_testing_1189_1',
                            'layout_params' => array
                            (
                                'image_layer' => 2,
                            ),
                        ),
                    ),

                ),
            ),
        );



        $rs = $this->_sendRequest($url, json_encode($data));
        p($rs, $data);
    }


    public function query()
    {
        $key = '127d4fe7e9f253375ad9e60e9315b5f8';
        $t = strtotime('+1 days');
        $appid = '1253714904';

        $sign = md5($key.$t);

        $url = "http://statcgi.video.qcloud.com/common_access?cmd=$appid&interface=Get_LivePushStat&t=$t&sign=$sign";
        $data = array
        (
            /*
            'appid'=> $appid,
            'interface' => 'Get_LivePushStat',
            't' => $t,
            'sign' => $sign,
            //*/
            'Param.n.page_no' => 1,
            'Param.n.page_size' => 20,
            'Param.s.stream_id' => '9342_testing_1373_2',
        );


        $rs = $this->_sendRequest($url, json_encode($data));
        p($url, $rs, $data);
    }

    
    protected static function _sendRequest($url, $paramArray, $method = 'POST')
    {
    
    	$ch = curl_init();
    
    	if ($method == 'POST')
    	{
    		$paramArray = is_array( $paramArray ) ? http_build_query( $paramArray ) : $paramArray;
    		curl_setopt($ch, CURLOPT_POST, 1);
    		curl_setopt($ch, CURLOPT_POSTFIELDS, $paramArray);
    	}
    	else
    	{
    		$url .= '?' . http_build_query($paramArray);
    	}
    
    	curl_setopt($ch, CURLOPT_URL, $url);
    	curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
    	if (false !== strpos($url, "https")) {
    		// 证书
    		// curl_setopt($ch,CURLOPT_CAINFO,"ca.crt");
    		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,  false);
    		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  false);
    	}
    	$resultStr = curl_exec($ch);
    
    	$result = json_decode($resultStr, true);
    	if (!$result)
    	{
    		return $resultStr;
    	}
    	return $result;
    }


    public function t()
    {
        $this->load->model('common/Model_api_access_log', 'v');
        $this->v->show_all_field();
    }

    public function tools()
    {
        $this->load->model('user/Model_user', 'u');
        $this->load->model('user/Model_user_info', 'ui');


        $user_data = $this->ui->lists(0, 20000, array(), true,'ui_id asc');
        foreach ($user_data as $v)
        {
            $sql = 'update sk_user set sex='.$v['sex'].' where uid='.$v['uid'];
            $rs = $this->u->query($sql, false);
            //d($rs);
            //$this->u->save(array('sex' => $v['sex']), $v['uid']);
        }
        //p($user_data);
    }


    public function to_app()
    {
        $this->load->view('www/test/to_app');
    }
}